package org.openmore.storage.oss.utils;

import org.openmore.storage.entity.enums.ResourceType;

public class OssFileUtils {

    /**
     * 图片文件匹配正则
     */
    private static final String IMAGE_MATCH = "^(.JPG)|(.JPEG)|(.PNG)|(.GIF)|(.BMP)|(.TIF)|(.SVG)|(.PSD)$";
    /**
     * 音频文件匹配正则
     */
    private static final String AUDIO_MATCH = "^(.MP3)|(.M4A)|(.WAV)|(.AMR)|(.AWB)|(.WMA)|(.OGG)|(.MID)|(.WMV)$";
    /**
     * 视频文件匹配正则
     */
    private static final String VIDEO_MATCH = "^(.VOB)|(.IOF)|(.MPG)|(.MPEG)|(.DAT)|(.MP4)|(.3GP)|(.MOV)|(.RM)|" +
            "(.RAM)|(.RMVB)|(.WMV)|(.ASF)|(.AVI)|(.ASX)$";

    public static ResourceType getResourceType(String fileName) {
        String fileExtension = fileName.substring(fileName.lastIndexOf("."));
        if(fileExtension.toUpperCase().matches(IMAGE_MATCH)){
            return ResourceType.IMAGE;
        }
        else if(fileExtension.toUpperCase().matches(AUDIO_MATCH)){
            return ResourceType.AUDIO;
        }
        else if(fileExtension.toUpperCase().matches(VIDEO_MATCH)){
            return ResourceType.VIDEO;
        }
        return ResourceType.OTHERS;
    }
}
